package dream.sword_offer.simple;

/**
 * projectName:java-garden
 * see:dream.sword_offer.simple
 * createTime:2021/9/10 10:16
 * author: Jiading chen
 * description: 剑指 Offer 05. 替换空格
 *
 * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 */
public class ReplaceSpace {
    public String replaceSpace(String s) {
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != ' ') {
                ans.append(s.charAt(i));
            } else {
                ans.append("%20");
            }
        }
        return ans.toString();
    }
}
